#ifndef __VIDEOPLAYER_H
#define __VIDEOPALYER_H

#define SDL_AUDIO_BUFFER_SIZE 1024
#define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
#define MAX_VIDEOQ_SIZE (5 * 256 * 1024)

#define FF_ALLOC_EVENT (SDL_USEREVENT)
#define FF_REFRESH_EVENT (SDL_USEREVENT + 1)
#define FF_QUIT_EVENT (SDL_USEREVENT + 2)

#define VIDEO_PICTURE_QUEUE_SIZE 1




typedef struct PacketQueue{
        AVPacketList *first_pkt, *last_pkt;
        int nb_packets;
        int size;
        SDL_mutex *mutex;
        SDL_cond *cond;



} PacketQueue;

typedef struct VideoPicture {
	SDL_Overlay *bmp;
	int width,height;
	int allocated;

}VideoPicture;



typedef struct VideoState{
        AVFormatContext *pFormatCtx;
        int             videoStream, audioStream;
        AVStream        *audio_st;
        PacketQueue     audioq;
        uint8_t         audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
        unsigned int    audio_buf_size;
        unsigned int    audio_buf_index;
        AVPacket        audio_pkt;
        uint8_t         *audio_pkt_data;
        int             audio_pkt_size;
        AVStream        *video_st;
        PacketQueue     videoq;

	VideoPicture    pictq[VIDEO_PICTURE_QUEUE_SIZE];

        int             pictq_size, pictq_rindex, pictq_windex;
        SDL_mutex       *pictq_mutex;
        SDL_cond        *pictq_cond;

        SDL_Thread      *parse_tid;
        SDL_Thread      *video_tid;

        char            filename[1024];
        int             quit;

}VideoState;



int video_thread(void *arg);
int decode_thread(void *arg);
void packet_queue_init(PacketQueue *q);
static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block);
int packet_queue_put(PacketQueue *q, AVPacket *pkt);
static void schedule_refresh(VideoState *is, int delay);
int queue_picture(VideoState *is, AVFrame *pFrame);
void alloc_picture(void *userdata);
void video_refresh_timer(void *userdata);
static void schedule_refresh(VideoState *is, int delay);
static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque);
void video_display(VideoState *is);
int decode_interrupt_cb(void);
int stream_component_open(VideoState *is, int stream_index);


int audio_decode_frame(VideoState *is, uint8_t *audio_buf, int buf_size);
int audio_callback(void *userdata, Uint8 *stream, int len);
#endif
